import type {Directive} from "vue";
import router from "@/router";
import Local from "@/utils/local";
import type {LoginSubmitResponsePermissionTreeDTOListType} from "@/types/loginType.ts";
import {getTreeItem} from "@/utils";


const has: Directive<HTMLElement, string> = (el, binding) => {
    const menuName: string = router.currentRoute.value.name as string;
    const menu:LoginSubmitResponsePermissionTreeDTOListType[] = JSON.parse(Local.localRead('menuList'))
    const row = getTreeItem<LoginSubmitResponsePermissionTreeDTOListType, string>(menu, menuName, 'componentName', 'children')
    if (row?.children){
        const item = row?.children.find(item => item.status === '1' && item.perms === binding.value)
        if (!item) {
            el.style.display = 'none'
        }
    } else {
        el.style.display = 'none'
    }
}
export default has